package cn.wl.hrm.web.controller;

import cn.wl.hrm.util.AjaxResult;
import cn.wl.hrm.utils.RedisUtils;
import org.springframework.web.bind.annotation.*;
//操作redis
@RestController
public class RedisController {

    //@RequestParam("key"):从请求参数中获取名字为key的数据
    @RequestMapping(value = "/redis/set",method = RequestMethod.POST)
    public AjaxResult set(@RequestParam("key") String key, @RequestParam("value") String value){
        RedisUtils.INSTANCE.set(key,value);
        return AjaxResult.me();
    }
    //设置过期时间
    @RequestMapping(value = "/redis/setex",method = RequestMethod.POST)
    public AjaxResult setex(@RequestParam("key") String key,@RequestParam("seconds") int seconds, @RequestParam("value") String value){
        RedisUtils.INSTANCE.setex(key,seconds,value);
        return AjaxResult.me();
    }


    //@PathVariable("key") :从 url中获取参数
    @RequestMapping(value = "/redis/get/{key}",method = RequestMethod.GET)
    public AjaxResult get(@PathVariable("key") String key){
        String result = RedisUtils.INSTANCE.get(key);
        return AjaxResult.me().setResultObj(result);
    }
}
